//
//  kWTailorItem.m
//  EasyToTesco2.0
//
//  Created by 杨森 on 2017/5/30.
//  Copyright © 2017年 EasyToTesco. All rights reserved.
//

#import "kWTailorItem.h"
#import "kWHomeModel.h"

@interface kWTailorItem()

@property(nonatomic,strong)UIImageView   *contentImg;
@property(nonatomic,strong)UILabel       *contentLabel;
@property(nonatomic,strong)UIButton      *collectBtn;
@property(nonatomic,strong)UIButton      *favourBtn;
@property(nonatomic,strong)UIButton      *commentBtn;

@end

@implementation kWTailorItem


- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        [self buildSubViews];
    }
    return self;
}

- (void)buildSubViews
{
    [self.contentView addSubview:self.contentImg];
    [self.contentView addSubview:self.contentLabel];
    [self.contentView addSubview:self.favourBtn];
    [self.contentView addSubview:self.collectBtn];
    [self.contentView addSubview:self.commentBtn];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.contentImg.frame = CGRectMake(15,0,self.width-30, self.Height*0.8);
    
    WeakSelf(self);
    [self.favourBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakself.contentImg).offset(5);
        make.top.equalTo(weakself.contentImg.mas_bottom).offset(5);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(15);
    }];
    
    [self.collectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakself.favourBtn.mas_right).offset(10);
        make.centerY.equalTo(weakself.favourBtn);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(15);
    }];
    
    [self.commentBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakself.collectBtn.mas_right).offset(10);
        make.centerY.equalTo(weakself.favourBtn);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(15);
    }];
    
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakself.contentImg);
        make.bottom.equalTo(weakself);
        make.width.equalTo(weakself.contentImg);
    }];
    
}

- (void)setHomeModel:(kWHomeModel *)homeModel
{
    _homeModel = homeModel;
    NSURL *url = [NSURL URLWithString:homeModel.img];
    [self.contentImg sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeholder"]];
    self.contentLabel.text = homeModel.title;
}


#pragma mark lazy
- (UIImageView *)contentImg
{
    if (!_contentImg) {
        _contentImg = [[UIImageView alloc] init];
        _contentImg.image = [UIImage imageNamed:@"kW_3d_bg"];
    }return _contentImg;
}


- (UILabel *)contentLabel
{
    if (!_contentLabel) {
        _contentLabel = [[UILabel alloc] init];
        _contentLabel.font = FONT(14);
        _contentLabel.textAlignment = NSTextAlignmentLeft;
        _contentLabel.text = @"凌波阁欧式橱柜";
    }
    return _contentLabel;
}

- (UIButton *)favourBtn
{
    if (!_favourBtn) {
        _favourBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_favourBtn setTitle:@"19" forState:UIControlStateNormal];
        [_favourBtn setImage:[UIImage imageNamed:@"home_dianZan"] forState:UIControlStateNormal];
        _favourBtn.titleLabel.font = FONT(12);
        [_favourBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        _favourBtn.imageEdgeInsets = UIEdgeInsetsMake(0,0,0,20);
    }
    return _favourBtn;
}

- (UIButton *)collectBtn
{
    if (!_collectBtn) {
        _collectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_collectBtn setTitle:@"收藏" forState:UIControlStateNormal];
        [_collectBtn setImage:[UIImage imageNamed:@"home_collection"] forState:UIControlStateNormal];
        _collectBtn.titleLabel.font = FONT(11);
        [_collectBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        _collectBtn.imageEdgeInsets = UIEdgeInsetsMake(0,0,0,10);
    }
    return _collectBtn;
}

- (UIButton *)commentBtn
{
    if (!_commentBtn) {
        _commentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _commentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_commentBtn setTitle:@"评论" forState:UIControlStateNormal];
        [_commentBtn setImage:[UIImage imageNamed:@"home_comment"] forState:UIControlStateNormal];
        _commentBtn.titleLabel.font = FONT(11);
        [_commentBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        _commentBtn.imageEdgeInsets = UIEdgeInsetsMake(0,0,0,10);

    }
    return _commentBtn;
}


@end
